print('displaying simulation results')
import numpy as np

def display_transient_parameters():
    from initialize_output_parameters import number_of_sampled_electric_fields
    from define_output_parameters import sampled_electric_fields
    from define_problem_space_parameters import number_of_time_steps
    print('plotting the transient parameters')
    #取样电场的图
    for ind in np.arange(number_of_sampled_electric_fields):
        sampled_time=sampled_electric_fields[ind]["time"][:number_of_time_steps]*1e9
        sampled_value=sampled_electric_fields[ind]["sampled_value"][:number_of_time_steps]
        data = np.zeros((number_of_time_steps,2))
        data[:,0] = sampled_time
        data[:,1] = sampled_value
        fileName = f'results_{ind}.txt'
        f = open(fileName,'w')
        f.write('t(ns) value\n')
        np.savetxt(f,data,fmt='%12.4f')
        f.close()
        #plot(sampled_time,sampled_value(1:time_step),'b-','linewidth',1.5)
    #    number_of_time_step = 1500
    # time = dt*[1:number_of_time_step]*1e9
    # #    time=([1:number_of_time_steps])*dt
    #    t_0=2e-9
    #     r=10*dx
    #    for time_step=1:number_of_time_step
    #         p=1e-10*exp(-((dt*time_step-r/c-3*t_0)/t_0).^2)
    # #     time=time*1e9
    #     dft=-2e-10*(dt*time_step-r/c-3*t_0)/(t_0^2).*exp(-((dt*time_step-r/c-3*t_0)/t_0).^2)#函数解析式
    #     dft_2=4e-10*(dt*time_step-r/c-3*t_0).^2/(t_0^4).*exp(-((dt*time_step-r/c-3*t_0)/t_0).^2)-2e-10/(t_0^2).*exp(-((dt*time_step-r/c-3*t_0)/t_0).^2)
    #     El_exact=(mu_0/(4*pi*r))*(dft_2+c/r*dft+c^2/r^2*p) 
    #    end
    #     plot(time,El_exact,'r-','linewidth',1.5)
    #  t_0=2e-9
    # 
    # # dx=2.5e-2
    # # dt=dx/(2*c)
    #     r=0.5
    # #       r=8*dx
    # #       r=12*dx
    #     time=([1:number_of_time_steps])*(2.5e-2/(2*3e8))
    #         p=1e-10*exp(-((time-r/c-3*t_0)/t_0).^2)
    #   
    #     dft=-2e-10*(time-r/c-3*t_0)/(t_0^2).*exp(-((time-r/c-3*t_0)/t_0).^2)#函数解析式
    #     dft_2=4e-10*(time-r/c-3*t_0).^2/(t_0^4).*exp(-((time-r/c-3*t_0)/t_0).^2)-2e-10/(t_0^2).*exp(-((time-r/c-3*t_0)/t_0).^2)
    #           time=time*1e9
    # if ind==1
    #     exact=(mu_0/(4*pi*r))*(dft_2+c/r*dft+c^2/r^2*p)
    # elseif(ind==2)
    #     exact=(mu_0/(4*pi*r))*-2*(c/r*dft+c^2/r^2*p)
    # end
    # 
    #        plot(time,exact,'r-','linewidth',1.5)
    # 
    #    
    #        
    #        legend('sampledvalue', 'exact','FontName','Times New Roman','FontSize',18,'LineWidth',1.5)
    # eps_0 = 8.854187817e-12 # permittivity of free space               
    # mu_0  = 4*pi*1e-7 # permeability of free space                    
    # c = 1/sqrt(mu_0*eps_0) # speed of light in free space
    # # dt = 0.8*0.5*0.03/c
    # T = 2e-9
    # R = 0.05*10 # distance
    # sita = pi/2
    # 
    # 
    # number_of_time_step = 1500
    # time = dt*[1:number_of_time_step]*1e9
    # for time_step = 1:number_of_time_step 
    #     P1 = 1e-10.*exp(-((dt.*time_step - 3*T)/T).^2)
    #     P2 = 1e-10.*exp(-(((dt.*time_step - R/c) - 3*T)/T).^2)
    #     temp = (-2)*(((dt.*time_step - R/c) - 3*T)/T^2)
    #     E1(time_step) = sin(sita)*((c/R)^2*P2 + c/R*P2*temp + P2*(temp^2 + (-2)/T^2))
    #     E2(time_step) = 2*cos(sita) * ((c/R)^2*P2 + c/R*P2*temp)
    #     E(time_step) = mu_0/(4*pi*R)*(E1(time_step) + E2(time_step))
    #    
    # end
    # plot(time,E,'linewidth',1.5)

    # #取样磁场的图
    # for ind=1:number_of_sampled_magnetic_fields
    #     if sampled_magnetic_fields(ind).display_plot==false
    #         sampled_magnetic_fields(ind).figure_number=figure
    #         xlabel('time(ns)','fontsize',12)
    #         ylabel('(ampere/meter)','fontsize',12)
    #         title(['sampled magnetic field[' num2str(ind) ']'],'fontsize',12)
    #         grid onhold on
    #     else
    #         figure(sampled_magnetic_fields(ind).figure_number)
    #         delete(sampled_magnetic_fields(ind).plot_handle)
    #     end
    #     sampled_time=sampled_magnetic_fields(ind).time(1:time_step)*1e9
    #     sampledd_value=sampled_magnetic_fields(ind).sampled_value(1:time_step)
    #     plot(sampled_time,sampled_value(1:time_step),'b-','linewidth',1.5)
    #     drawnow
    # end
    # 取样电压的图
    # for ind=1:number_of_sampled_voltages
    #     if sampled_voltages(ind).display_plot==false
    #         sampled_voltages(ind).figure_number=figure
    #         xlabel('time(ns)','fontsize',12)
    #         ylabel('(volt)','fontsize',12)
    #         title(['sampled voltage[' num2str(ind) ']'],'fontsize',12)
    #         grid onhold on
    #     else
    #         figure(sampled_voltages(ind).figure_number)
    #         delete(sampled_voltages(ind).plot_handle)
    #     end
    #     sampled_time=sampled_voltages(ind).time(1:time_step)*1e9
    #     sampled_value=sampled_voltages(ind).sampled_value(1:time_step)
    #     plot(sampled_time,sampled_value(1:time_step),'b-','linewidth',1.5)
    #     drawnow
    # end
    #取样电流的图
    # for ind=1:number_of_sampled_currents
    #     if sampled_currents(ind).display_plot==false
    #         sampled_currents(ind).figure_number=figure
    #         xlabel('time(ns)','fontsize',12)
    #         ylabel('(ampere)','fontsize',12)
    #         title(['sampled current[' num2str(ind) ']'],'fontsize',12)
    #         grid onhold on
    #     else
    #         figure(sampled_currents(ind).figure_number)
    #         delete(sampled_currents(ind).plot_handle)
    #     end
    #     sampled_time=sampled_currents(ind).time(1:time_step)*1e9
    #     sampled_value=sampled_currents(ind).sampled_value(1:time_step)
    #     plot(sampled_time,sampled_value(1:time_step),'b-','linewidth',1.5)
    #     drawnow
    # end

    #电压源的图
    # for ind=1:number_of_voltage_sources
    #         time=([1:number_of_time_steps])*dt
    #     voltages_sources(ind).figure_number=figure
    #     sampled_time=time(1:time_step)*1e9
    #     sampled_value=voltage_sources(ind).waveform(1:time_step)
    #     plot(sampled_time,sampled_value(1:time_step),'r-','linewidth',1.5)
    #     xlabel('time(ns)','fontsize',12)
    #     ylabel('(volt)','fontsize',12)
    #     title(['Voltage Source[' num2str(ind) ']'],'fontsize',12)
    #     grid on
    #     drawnow
    # end

    # #电流源的图
    # for ind=1:number_of_current_sources
    #     current_sources(ind).figure_number=figure
    #     sampled_time=time(1:time_step)*1e-9
    #     sampled_value=current_sources(ind).waveform(1:time_step)
    #     plot(sampled_time,sampled_value(1:time_step),'r-','linewidth',1.5)
    #     xlabel('time(ns)','fontsize',12)
    #     ylabel('(ampere)','fontsize',12)
    #     title(['Current Source[' num2str(ind) ']'],'fontsize',12)
    #     grid on
    #     drawnow
    # end

display_transient_parameters()